let v = new Vue({
    el:'#main-container',
    data:function () {
        return {
            pageInfo:{
                pageSize:5
            },
            params:{
                status:''
            },
            settings:{
                data:{
                    simpleData: {
                        enable:true,
                        pIdKey:'parentId'
                    }
                },
                callback:{
                    onClick:this.onClick
                },
                view:{
                    fontCss:this.fontCss
                }
            },
            nodes:[],
            name:'全部',
            searchName:''
        }
    },
    methods:{
        selectByCondition:function (page,pageSize) {
            axios({
                url:`manager/work/list/${page}/${pageSize}`,
                data:this.params,
                method:'post'
            }).then(resp => {
                this.pageInfo = resp.data.obj;
            }).catch(error => {
                console.log(error);
            })
        },
        findAll:function (page,pageSize) {
            this.params = {status:''};
            this.selectByCondition(page,pageSize);
        },
        initTree:function () {
            axios({
                url:'manager/office/list',
                method: 'get'
            }).then(resp => {
                this.nodes = resp.data.obj;
                this.nodes[this.nodes.length] = {id:0,name:'全部',open:true};
                let treeObj = $.fn.zTree.init($("#pullDownTreeone"),this.settings,this.nodes)
                console.log(treeObj);
            }).catch(error => {
                console.log(error);
            });

        },
        onClick:function (event,treeId,treeNode) {
            this.name = treeNode.name;
            if(0 != treeNode.id){
                this.params.officeId = treeNode.id;
            }else{
                this.params.officeId = '';
            }

        },
        findByName:function () {
            let tree = $.fn.zTree.getZTreeObj('pullDownTreeone');
            let notes = tree.transformToArray(tree.getNodes());
            let needNotes = tree.getNodesByParamFuzzy("name",this.searchName,null);
            for (let i in notes) {
                notes[i].hightLight = false;
                tree.updateNode(notes[i]);
            }
            for (let i in needNotes) {
                for(let j in notes){
                    if(needNotes[i].id == notes[j].id){
                        notes[j].hightLight = true;
                        tree.updateNode(notes[j]);
                        break;
                    }
                }
            }
        },
        fontCss:function (treeId,treeNode) {
            return treeNode.hightLight?{color:'red'}:{color:'black'};
        },
        toDetail:function (id) {
            layer.obj = id;
            layer.open({
                type: 2,
                title: '详情',
                area: ['60%', '60%'],
                content: 'manager/work/toDetail',
                end:() => {
                    // if(!layer.success){
                    //     this.findAll(1,this.pageInfo.pageSize);
                    // }
                }
            })
        }
    },
    created:function () {
        this.findAll(1,this.pageInfo.pageSize);
    },
    mounted:function(){
        this.initTree();
    }
})